<?php

namespace App\Admin\Controllers;

use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class AdminBaseController extends AdminController
{
    public function gridFilter(Grid $grid, $name, $self = false)
    {
        $model = $grid->model();
        if (Admin::user()->isAdministrator()) {
        } else {
            $admin_id = Admin::user()->id;
            if ($self) {
                $model->whereRaw("FIND_IN_SET($admin_id,agent_path)");
            } else {
                $model->leftJoin('users', 'users.id', '=', 'uid')->select(["$name.*", "users.agent_path"])->whereRaw("FIND_IN_SET($admin_id,agent_path)");
            }
        }
    }
}
